package xyz.jiang.asteroid.service.impl;


import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import xyz.jiang.asteroid.common.base.RestResponse;
import xyz.jiang.asteroid.pojo.dto.UserDTO;
import xyz.jiang.asteroid.service.LoginService;

@Service
public class LoginServiceImpl implements LoginService {

    private final AuthenticationManager authenticationManager;
    LoginServiceImpl(AuthenticationManager authenticationManager){
        this.authenticationManager = authenticationManager;
    }


    public RestResponse login(UserDTO userDTO) {
        UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(userDTO.getUsername(),userDTO.getPassword());
        Authentication authenticate = authenticationManager.authenticate(authenticationToken);
        return RestResponse.success(authenticate);
    }
}
